package com.xunker.appointment.controller;

import com.xunker.appointment.model.hospital.Hospital;
import com.xunker.appointment.model.hospital.HospitalSet;
import com.xunker.appointment.model.schedule.Schedule;
import com.xunker.appointment.result.Result;
import com.xunker.appointment.service.HospitalService;
import com.xunker.appointment.service.ScheduleService;
import com.xunker.appointment.vo.hospital.HospitalSetVo;
import com.xunker.appointment.vo.hospital.HospitalVo;
import com.xunker.appointment.vo.hospital.ProAndCityVo;
import com.xunker.appointment.vo.order.ScheduleOrderVo;
import com.xunker.appointment.vo.order.SignInfoVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Api(tags = "医院接口")
@RestController
@RequestMapping("admin/hospital")
public class HospitalController {
    @Autowired
    private HospitalService hospitalService;
    @Autowired
    private ScheduleService scheduleService;
    //医院列表
    @PostMapping("list/{page}/{limit}")
    public Result list(@PathVariable Integer page, @PathVariable Integer limit, @RequestBody(required = false) HospitalVo hospitalVo){
        Map<String,Object> hospitalPage=hospitalService.getHospitalPage(page,limit,hospitalVo);
        return Result.ok(hospitalPage);
    }
    //省和城市
    @GetMapping("getProAndCity/{dictoryCode}/{value}")
    public Result getProAndCity( @PathVariable String dictoryCode, @PathVariable String value){
        ArrayList<ProAndCityVo> proAndCityVos=hospitalService.getProAndCity(dictoryCode,value);
        return Result.ok(proAndCityVos);
    }
    //医院详情
    @PostMapping("rule")
    public Result rule( @RequestBody(required = false) HospitalVo hospitalVo){
        Map<String,Object> rule=hospitalService.getHospitalRule(hospitalVo);
        return Result.ok(rule);
    }
    @ApiOperation(value = "获取可预约排班数据")
    @GetMapping("auth/getBookingScheduleRule/{page}/{limit}/{hoscode}/{depcode}")
    public Result getBookingSchedule(
            @ApiParam(name = "page", value = "当前页码", required = true)
            @PathVariable Integer page,
            @ApiParam(name = "limit", value = "每页记录数", required = true)
            @PathVariable Integer limit,
            @ApiParam(name = "hoscode", value = "医院code", required = true)
            @PathVariable String hoscode,
            @ApiParam(name = "depcode", value = "科室code", required = true)
            @PathVariable String depcode) throws ParseException {
        return Result.ok(scheduleService.getBookingScheduleRule(page, limit, hoscode, depcode));
    }

    @ApiOperation(value = "获取排班数据")
    @GetMapping("auth/findScheduleList/{hoscode}/{depcode}/{workDate}")
    public Result findScheduleList(
            @ApiParam(name = "hoscode", value = "医院code", required = true)
            @PathVariable String hoscode,
            @ApiParam(name = "depcode", value = "科室code", required = true)
            @PathVariable String depcode,
            @ApiParam(name = "workDate", value = "排班日期", required = true)
            @PathVariable String workDate) {
        return Result.ok(scheduleService.getDetailSchedule(hoscode, depcode, workDate));
    }
    @ApiOperation(value = "根据排班id获取排班数据")
    @GetMapping("getSchedule/{scheduleId}")
    public Result getSchedule(
            @ApiParam(name = "scheduleId", value = "排班id", required = true)
            @PathVariable("scheduleId") String scheduleId) {
        Schedule schedule=scheduleService.getById(scheduleId);
        return Result.ok(schedule);
    }
}
